package com.thb.pay.payment.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.thb.pay.api.payment.AgentpayPassageServiceApi;
import com.thb.pay.api.payment.vo.req.AgentpayPassagePageReq;
import com.thb.pay.api.payment.vo.req.AgentpayPassageReq;
import com.thb.pay.api.payment.vo.resp.AgentpayPassageVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.db.entity.SuperEntity;
import com.thb.pay.payment.entity.AgentpayPassage;
import com.thb.pay.payment.service.AgentpayPassageService;
import com.xiaoleilu.hutool.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 代付-通道表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@RestController
public class AgentpayPassageController implements AgentpayPassageServiceApi {

    @Autowired
    private AgentpayPassageService agentpayPassageService;

    @Override
    public PageResult<AgentpayPassageVo> findPage(@RequestBody AgentpayPassagePageReq pageReq) {
        return agentpayPassageService.findPage(pageReq);
    }

    @Override
    public List<AgentpayPassageVo> findAllList() {
        return agentpayPassageService.findAllList(null);
    }

    @Override
    public AgentpayPassageVo getById(@RequestParam("id") Long id) {
        return agentpayPassageService.getById(id);
    }

    @Override
    public void add(@RequestBody AgentpayPassageReq agentpayPassageReq) {
        agentpayPassageService.add(agentpayPassageReq);
    }

    @Override
    public void update(@RequestBody AgentpayPassageReq agentpayPassageReq) {
        agentpayPassageService.update(agentpayPassageReq);
    }

    @Override
    public void deleteBatchIds(@RequestBody List<Long> ids) {
        LambdaQueryWrapper<AgentpayPassage> wrapper = new LambdaQueryWrapper();
        wrapper.in(AgentpayPassage::getId, ids);
        List<AgentpayPassage> targetDbResultList = agentpayPassageService.selectList(wrapper);
        if (CollUtil.isNotEmpty(targetDbResultList)) {
            targetDbResultList.forEach(payType -> {
                payType.setDelFlag(SuperEntity.DEFAULT_DELETE_FLAG);
            });
            agentpayPassageService.updateBatchById(targetDbResultList);
        }
    }
}
